package com.qys.filedao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.qys.filejdbc.JDBC;

public class fileDao {
	public void insert(String filename) throws SQLException {
		Connection c = JDBC.getc();
		String sql = "insert into upfile(filename) values(?)";
		PreparedStatement ps = c.prepareStatement(sql);
		ps.setString(1, filename);
		ps.executeUpdate();
		ps.close();c.close();
	}
	
	
	public int proving(String filename) throws SQLException{
		Connection c = JDBC.getc();
		String sql = "select count(*) num from upfile where filename=?";
		PreparedStatement ps = c.prepareStatement(sql);
		ps.setString(1, filename);
		ResultSet r = ps.executeQuery();
		int num = 0;
		if(r.next()){
			 num = r.getInt("num");
		}
		r.close();ps.close();c.close();
		return num;
	}
	public void insertDown(String filename,double filesize) throws SQLException {
		Connection c = JDBC.getc();
		String sql = "insert into file(filename,filesize) values(?,?)";
		PreparedStatement ps = c.prepareStatement(sql);
		ps.setString(1, filename);
		ps.setDouble(2, filesize);
		ps.executeUpdate();
		ps.close();c.close();
	}
	
}
